/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package net.tygzs.minerpg.lib;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author thtTNT
 */
public class MathLib
{

    public static double cutDouble(int index, double vaule)
    {
        BigDecimal bd = new BigDecimal(vaule);
        return bd.setScale(index, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

    public static List<Map.Entry<String, Integer>> rankMapUp(Map map)
    {
        List<Map.Entry<String, Integer>> mappingList = null;
        mappingList = new ArrayList<>(map.entrySet());
        Collections.sort(mappingList, new Comparator<Map.Entry<String, Integer>>()
        {
            @Override
            public int compare(Map.Entry<String, Integer> mapping1, Map.Entry<String, Integer> mapping2)
            {
                return mapping1.getValue().compareTo(mapping2.getValue());
            }
        });
        return mappingList;
    }
}
